clear
clear matrix
set more off
use "C:\Users\mjoshi2.DSS-OKIU3QJMAS9\Desktop\Accepted-Final Articles 2014\Negotiation Journal\Negotiaiton Journal\data and do files\Joshi-Quinn-PA Data 5DEC2013.dta", clear 
log using "C:\Users\mjoshi2.DSS-OKIU3QJMAS9\Desktop\Accepted-Final Articles 2014\Negotiation Journal\Negotiaiton Journal\data and do files\log.smcl", replace

//use "C:\Users\mjoshi2\Google Drive\MESH FILES (1)\2013 Working Projects\UCDP Peace Agreement Data\UCDP PeaceAgreement Data\Peace Agreement Data 2012\APSR Revisions\Joshi-Quinn-PA Data Final v. 13March2013.dta", clear 

//use "C:\Users\mjoshi2\Documents\USEFUL DATA\UCDP Peace Agreement Data\UCDP PeaceAgreement Data\UCDP_PAM.dta", clear

//Generate Whether the conflict is territorial or government
gen terri_inco = 1 if inc ==1
replace terri_inc=0 if  terri_inco ==.
label variable terri_inco "Territorial Incompatibility if inc ==1"

//Generate Interaction with Territorial Incompatibility and Local government

replace dyvi05 = . if dyvi05==-99

//Categorizing variables for �Are there outstanding issues specified in the agreement?�
gen outstanding_issue_identified = 1 if out_iss==2 
replace outstanding_issue_identified = 0 if  outstanding_issue_identified==.
label variable outstanding_issue_identified "Outstanding issue if out_iss==2"


gen process_agree = 1 if out_iss==1
replace process_agree=0 if process_agree==.
label variable process_agree "Process Agreement if out_iss ==1"

gen del_to_commissino = 1 if out_iss==3
replace  del_to_commissino = 0 if  del_to_commissino ==.
label variable del_to_commissino "Outstanding Issues delegated to Commission out_iss ==3"

gen new_negotiation = 1 if out_iss==4
replace new_negotiation = 0 if new_negotiation==.

gen negotiating_agenda = 0
replace negotiating_agenda = 1 if  out_iss ==5

//Generate Individual PA type

gen full_pa =1 if pa_type==1
replace full_pa=0 if full_pa==.

gen partial_pa=0
replace partial_pa=1 if pa_type==2

//pwcorr dyvi05  total_prov intarmy   shagov  shaloc terri_inco  regdev locgov   locgov_terriinc  outstanding_issue_identified  process_agree  del_to_commissino negotiating_agenda pko  no_dyad pre_accord  full_pa partial_pa, sig star(0.05)

//Merge PAM and UCDP with common cases
gen pam_ucdptotal = total_p
replace pam_ucdptotal = pam if pam!=.

//Ways to address endogenity problem - mediation and prior accord 
//Mediation to address endogenitiy issue
gen mediation_1 = 0
replace mediation_1 = mediation if mediation!=.

//replace  pam_ucdptotal =  total_prov if  pam_ucdptotal==.
//order  pam_ucdptotal total_prov vi05_2, first

//creating a variable that has identified outstanding issues all from 1-5 in out_issue at UCDP

//gen outs_identified = 0
//replace outs_identified = 1 if out_iss ==0

gen outstanding_issue = 0
replace outstanding_issue = 1 if out_iss!=0

//Summary Stat

//FINAL FINAL Models -- cluster in country not conflict//this is a new change

//Mediating Outstanding Issues
gen med_out = mediation_1* outstanding_issue

 //Generate Log of Population
 gen  ln_pop = ln(pop_total)

 //Generate log of gdp_percapita 2000 constant USD

gen ln_gdp_percapita = ln(gdp_percapita_2000)

//Generate log of wardur in days  
gen ln_duration = log(wardur)

//Generate Conflict Intensity for major wars

gen major_war = 0
replace major_war=1 if intensity==2

//Interaction between cumulative accord and failure
gen cum_acc_fail =  cum_accord*cum_failure

//Replicate Table 1 : Summary Statistics

sum dyvi05 pam_ucdptotal total_prov  pa_lead_pa no_dyad pre_accord process terri_inco shaloc intgov pko intarmy mediation_1  ln_duration major_war   polity ethnic_fra  ln_pop ln_gdp infantmort_rate1000  

//Table 2
logit   pa_lead_pa  total_prov pre_accord, cl(ccode)
logit   pa_lead_pa  total_prov no_dyad pre_accord  terri_inco ln_duration major_war polity, cl(ccode)
logit   pa_lead_pa total_prov no_dyad pre_accord  terri_inco polity mediation_1  ethnic_fra  ln_pop ln_gdp  ln_duration major_war, cl(ccode)
logit   pa_lead_pa total_prov no_dyad pre_accord process terri_inco polity mediation_1  ethnic_fra  ln_pop infantmort_rate1000  ln_duration major_war, cl(ccode)

//Replicate Model 2, 3 and 4 with PAM data
logit  pa_lead_pa  pam_ucdptotal no_dyad pre_accord  terri_inco ln_duration major_war polity, cl(ccode)
logit   pa_lead_pa pam_ucdptotal no_dyad pre_accord  terri_inco polity mediation_1  ethnic_fra  ln_pop ln_gdp  ln_duration major_war, cl(ccode)
logit   pa_lead_pa pam_ucdptotal no_dyad pre_accord process terri_inco polity mediation_1  ethnic_fra  ln_pop infantmort_rate1000  ln_duration major_war, cl(ccode)


//Table 3, Model 1, 2, 3, 4, 5, 6 and 7
 

logit   dyvi05  total_p pre_accord, cl(ccode)
logit   dyvi05  total_p no_dyad pre_accord  terri_inco ln_duration major_war polity, cl(ccode)
logit   dyvi05 total_p no_dyad pre_accord  terri_inco polity mediation_1  ethnic_fra  ln_pop ln_gdp  ln_duration major_war, cl(ccode)
logit   dyvi05 total_p no_dyad pre_accord  terri_inco polity mediation_1  ethnic_fra  ln_pop infantmort_rate1000  ln_duration major_war, cl(ccode)

//Replicate Model 2, 3 and 4 with PAM data
logit   dyvi05  pam_ucdptotal no_dyad pre_accord  terri_inco ln_duration major_war polity, cl(ccode)
logit   dyvi05 pam_ucdptotal no_dyad pre_accord  terri_inco polity mediation_1  ethnic_fra  ln_pop ln_gdp  ln_duration major_war, cl(ccode)
logit   dyvi05 pam_ucdptotal no_dyad pre_accord  terri_inco polity mediation_1  ethnic_fra  ln_pop infantmort_rate1000  ln_duration major_war, cl(ccode)


//Table 4 - Robustness Tests 

gen provisions_loc_gov_army_pko = total_prov
replace provisions_loc_gov_army_pko =  provisions_loc_gov_army_pko-shaloc if shaloc==1
replace provisions_loc_gov_army_pko =  provisions_loc_gov_army_pko-intgov if intgov==1
replace provisions_loc_gov_army_pko =  provisions_loc_gov_army_pko-intarmy if intarmy==1
replace provisions_loc_gov_army_pko =  provisions_loc_gov_army_pko-pko if pko==1

logit dyvi05  provisions_loc_gov_army_pko  no_dyad pre_accord  terri_inco polity mediation_1 major_war  ethnic_fra  ln_pop infantmort_rate1000  ln_duration shaloc intgov pko intarmy , cl(ccode)

gen provisionsPAM_loc_gov_army_pko = pam_ucdptotal
replace provisionsPAM_loc_gov_army_pko =  provisionsPAM_loc_gov_army_pko-shaloc if shaloc==1
replace provisionsPAM_loc_gov_army_pko =  provisionsPAM_loc_gov_army_pko-intgov if intgov==1
replace provisionsPAM_loc_gov_army_pko=  provisionsPAM_loc_gov_army_pko-intarmy if intarmy==1
replace provisionsPAM_loc_gov_army_pko=  provisionsPAM_loc_gov_army_pko-pko if pko==1

logit   dyvi05 provisionsPAM_loc_gov_army_pko  no_dyad pre_accord  terri_inco polity mediation_1 major_war  ethnic_fra  ln_pop infantmort_rate1000  ln_duration shaloc intgov pko intarmy , cl(ccode)
//Robustness Tests - excludes PAM agreement and replicate Model 4
logit   dyvi05 total_prov no_dyad pre_accord  terri_inco polity mediation_1  ethnic_fra  ln_pop infantmort_rate1000  ln_duration major_war  if full!=1, cl(ccode)
//Robustness Tests - excludes process agreement and replicate Model 4 and Model 7
logit   dyvi05 total_p no_dyad pre_accord  terri_inco polity mediation_1  ethnic_fra  ln_pop infantmort_rate1000  ln_duration major_war  if pa_type!=3 , cl(ccode)
logit   dyvi05 pam_ucdptotal no_dyad pre_accord  terri_inco polity mediation_1  ethnic_fra  ln_pop infantmort_rate1000  ln_duration major_war  if pa_type!=3 , cl(ccode)



//Table 5 Marginal Effects
//Model 4 and 7  in Table 2 for negotiation in Future
logit   pa_lead_pa total_prov no_dyad pre_accord process terri_inco polity mediation_1  ethnic_fra  ln_pop infantmort_rate1000  ln_duration major_war, cl(ccode)

mfx compute, at (mean, total_prov=0)
mfx compute, at (mean, total_prov=21)

mfx compute, at (mean, no_dyad=1)
mfx compute, at (mean, no_dyad=3)

mfx compute, at (mean, pre_accord=0)
mfx compute, at (mean, pre_accord=1)

mfx compute, at (mean, process=0)
mfx compute, at (mean, process=1)

mfx compute, at (mean, terri_inco=0)
mfx compute, at (mean, terri_inco=1)

mfx compute, at (mean, mediation_1=0)
mfx compute, at (mean, mediation_1=1)

mfx compute, at (mean,  ln_duration = 2.64)
mfx compute, at (mean,  ln_duration = 9.81)

mfx compute, at (mean,  major_war = 0)
mfx compute, at (mean,  major_war = 1)

mfx compute, at (mean, polity=-9)
mfx compute, at (mean, polity=10)

mfx compute, at (mean, ethnic_fra = 0.25)
mfx compute, at (mean, ethnic_fra = 0.93) 

mfx compute, at (mean, ln_pop = 13.21)
mfx compute, at (mean, ln_pop = 20.63)

mfx compute, at (mean,  infantmort_rate1000 = 4.30)
mfx compute, at (mean,  infantmort_rate1000 = 161.30)

//Change in provisions
mfx compute, at (mean, total_prov=0)
mfx compute, at (mean, total_prov=3)
mfx compute, at (mean, total_prov=6)
mfx compute, at (mean, total_prov=9)
mfx compute, at (mean, total_prov=12)
mfx compute, at (mean, total_prov=15)
mfx compute, at (mean, total_prov=18)
mfx compute, at (mean, total_prov=21)

logit   pa_lead_pa pam_ucdptotal no_dyad pre_accord process terri_inco polity mediation_1  ethnic_fra  ln_pop infantmort_rate1000  ln_duration major_war, cl(ccode)

mfx compute, at (mean, pam_ucdptotal=0)
mfx compute, at (mean, pam_ucdptotal=43)

mfx compute, at (mean, no_dyad=1)
mfx compute, at (mean, no_dyad=3)

mfx compute, at (mean, pre_accord=0)
mfx compute, at (mean, pre_accord=1)

mfx compute, at (mean, process=0)
mfx compute, at (mean, process=1)

mfx compute, at (mean, terri_inco=0)
mfx compute, at (mean, terri_inco=1)

mfx compute, at (mean, mediation_1=0)
mfx compute, at (mean, mediation_1=1)

mfx compute, at (mean,  ln_duration = 2.64)
mfx compute, at (mean,  ln_duration = 9.81)

mfx compute, at (mean,  major_war = 0)
mfx compute, at (mean,  major_war = 1)

mfx compute, at (mean, polity=-9)
mfx compute, at (mean, polity=10)

mfx compute, at (mean, ethnic_fra = 0.25)
mfx compute, at (mean, ethnic_fra = 0.93) 

mfx compute, at (mean, ln_pop = 13.21)
mfx compute, at (mean, ln_pop = 20.63)

mfx compute, at (mean,  infantmort_rate1000 = 4.30)
mfx compute, at (mean,  infantmort_rate1000 = 161.30)

mfx compute, at (mean, pam_ucdptotal=0)
mfx compute, at (mean, pam_ucdptotal=3)
mfx compute, at (mean, pam_ucdptotal=6)
mfx compute, at (mean, pam_ucdptotal=9)
mfx compute, at (mean, pam_ucdptotal=12)
mfx compute, at (mean, pam_ucdptotal=15)
mfx compute, at (mean, pam_ucdptotal=18)
mfx compute, at (mean, pam_ucdptotal=21)



//Marginal Effect Based on Model 4 and Model 7 in Table 3
logit   dyvi05 total_p no_dyad pre_accord  terri_inco polity mediation_1  ethnic_fra  ln_pop infantmort_rate1000  ln_duration major_war, cl(ccode)
mfx compute, at (mean, total_prov=0)
mfx compute, at (mean, total_prov=21)

mfx compute, at (mean, no_dyad=1)
mfx compute, at (mean, no_dyad=3)

mfx compute, at (mean, pre_accord=0)
mfx compute, at (mean, pre_accord=1)

mfx compute, at (mean, terri_inco=0)
mfx compute, at (mean, terri_inco=1)

mfx compute, at (mean, mediation_1=0)
mfx compute, at (mean, mediation_1=1)

mfx compute, at (mean,  ln_duration = 2.64)
mfx compute, at (mean,  ln_duration = 9.81)

mfx compute, at (mean,  major_war = 0)
mfx compute, at (mean,  major_war = 1)

mfx compute, at (mean, polity=-9)
mfx compute, at (mean, polity=10)

mfx compute, at (mean, ethnic_fra = 0.25)
mfx compute, at (mean, ethnic_fra = 0.93) 

mfx compute, at (mean, ln_pop = 13.21)
mfx compute, at (mean, ln_pop = 20.63)

mfx compute, at (mean,  infantmort_rate1000 = 4.30)
mfx compute, at (mean,  infantmort_rate1000 = 161.30)

//Model 7
logit   dyvi05 pam_ucdptotal no_dyad pre_accord  terri_inco polity mediation_1  ethnic_fra  ln_pop infantmort_rate1000  ln_duration major_war, cl(ccode)

mfx compute, at (mean, pam_ucdptotal=0)
mfx compute, at (mean, pam_ucdptotal=43)

mfx compute, at (mean, no_dyad=1)
mfx compute, at (mean, no_dyad=3)

mfx compute, at (mean, pre_accord=0)
mfx compute, at (mean, pre_accord=1)

mfx compute, at (mean, terri_inco=0)
mfx compute, at (mean, terri_inco=1)

mfx compute, at (mean, mediation_1=0)
mfx compute, at (mean, mediation_1=1)

mfx compute, at (mean,  ln_duration = 2.64)
mfx compute, at (mean,  ln_duration = 9.81)

mfx compute, at (mean,  major_war = 0)
mfx compute, at (mean,  major_war = 1)

mfx compute, at (mean, polity=-9)
mfx compute, at (mean, polity=10)

mfx compute, at (mean, ethnic_fra = 0.25)
mfx compute, at (mean, ethnic_fra = 0.93) 

mfx compute, at (mean, ln_pop = 13.21)
mfx compute, at (mean, ln_pop = 20.63)

mfx compute, at (mean,  infantmort_rate1000 = 4.30)
mfx compute, at (mean,  infantmort_rate1000 = 161.30)

//Cumulative Marginal Effects of Peace Agreement 
logit   dyvi05 total_p no_dyad pre_accord  terri_inco polity mediation_1 ethnic_fra  ln_pop infantmort_rate1000  ln_duration major_war, cl(ccode)

mfx compute, at (mean, total_p=0)
mfx compute, at (mean, total_p=3)
mfx compute, at (mean, total_p=6)
mfx compute, at (mean, total_p=9)
mfx compute, at (mean, total_p=12)
mfx compute, at (mean, total_p=15)
mfx compute, at (mean, total_p=18)
mfx compute, at (mean, total_p=21)


//for vif tests use replace logit with collin and drop cl(ccode)
clear
clear matrix
log close



